import {Component, EventEmitter, Output} from '@angular/core';
import {AlertController, IonicPage, NavController, NavParams, Events} from 'ionic-angular';
import {CloseAccountTabPage} from "../close-account-tab/close-account-tab";
import {GuidePage} from "../../guide/guide";

/**
 * Generated class for the AddCountWayPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@Component({
    selector: 'page-add-count-way',
    templateUrl: 'add-count-way.html',
})
export class AddCountWayPage {
    jsWayLabel: string;
    way: string;
    account: string;
    openingBank: string;
    fee: string;
    accountNumber: string;
    jsWayList: any = [
        {
            name: '现金', bool: true
        },
        {
            name: '支票', bool: false
        },
        {
            name: '转账', bool: false
        }];
    jsInfoList: Array<any> = [];
    @Output() childEvent = new EventEmitter<any>();

    constructor(public navCtrl: NavController, public navParams: NavParams, public alertCtrl: AlertController, public event: Events) {
    }

    ionViewDidLoad() {
        console.log('ionViewDidLoad AddCountWayPage');
    }

    complete() {
        this.jsInfoList.push({
            'way': this.jsWayLabel,
            'fee': this.fee,
            'account': this.account,
            'openingBank': this.openingBank,
            'accountNumber': this.accountNumber
        });
        //localStorage.setItem('payWayList', JSON.stringify(this.jsInfoList));
       // this.navCtrl.pop();
        //this.event.publish('tab', 'tab3');
        this.navCtrl.push(GuidePage);
    }

    chooseCountWay() {
        let alert = this.alertCtrl.create();
        alert.setTitle('报销类型');

        this.jsWayList.forEach((value) => {
            console.log(value);
            alert.addInput({
                type: 'radio',
                label: value.name,
                value: value.name,
                checked: value.bool
            });
        });

        alert.addButton('取消');
        alert.addButton({
            text: '确定',
            handler: data => {
                this.jsWayLabel = data;
            }
        });
        alert.present();
    }
}
